<?php

namespace app\common\library;

use EasyWeChat\Factory;

class Mini
{
    private static $config = [
        'app_id' => 'wx4682ba92168146ba',
        'secret' => '112fb466264b7194ba5fcd9c08802023',
        'response_type' => 'array',
        'log' => [
            'level' => 'debug',
            'file' => __DIR__ . '/wechat.log',
        ]
    ];


    public static function app()
    {
        return Factory::miniProgram(self::$config);
    }

    public static function sendMessage($template_id, $touser, $data, $page = "")
    {
        $app = self::app();
        $data = [
            'template_id' => $template_id,// 所需下发的订阅模板id'bDmywsp2oEHjwAadTGKkUJ-eJEiMiOf7H-dZ7wjdw80',
            'touser' => $touser,   // 接收者（用户）的 openid  'oSyZp5OBNPBRhG-7BVgWxbiNZm',
            'page' => '',       // 点击模板卡片后的跳转页面，仅限本小程序内的页面。支持带参数,（示例index?foo=bar）。该字段不填则模板无跳转。
            'data' => $data,
// [         // 模板内容，格式形如 { "key1": { "value": any }, "key2": { "value": any } }
//                'character_string1' => [
//                    'value' => '',
//                ],
//                'amount2' => [
//                    'value' => 10,
//                ],
//                'character_string5' => [
//                    'value' => '2019-12-01',
//                ],
//                'thing7' => [
//                    'value' => 10,
//                ],
//                'time9' => [
//                    'value' => '2019-12-01',
//                ],
//            ],
        ];

        return $app->subscribe_message->send($data);
    }
}